# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=suitesparse
_pkgname=SuiteSparse
pkgver=5.10.1
pkgrel=0
pkgdesc="A collection of sparse matrix libraries"
url="http://faculty.cse.tamu.edu/davis/suitesparse.html"
arch="all"
license="GPL-3.0-only"
depends_dev="
	gmp-dev
	mpfr-dev
	openblas-dev
	"
makedepends="$depends_dev cmake m4"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-graphblas
	"
source="https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v$pkgver/$_pkgname-$pkgver.tar.gz
	0001-exclude-metis.patch
	0002-remove-rpath.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

_flags="BLAS=-lopenblas LAPACK=-lopenblas"

# Do not include the Partition module and METIS (it's optional and
# Julia doesn't need it).
# Do not try to override optimization level. SuiteSparse is a huge library
# heavily optimized for performance, so compiling with -Os doesn't make sense.
# Actually, the build scripts currently override -Os with -O3 anyway,
# but better to not rely on it.
export CFLAGS="${CFLAGS/-Os/} -DNPARTITION"
export CPPFLAGS=${CPPFLAGS/-Os/}
export CXXFLAGS=${CXXFLAGS/-Os/}

prepare() {
	rm -r metis-*

	default_prepare
}

build() {
	make library $_flags CMAKE_OPTIONS="\
		-DCMAKE_INSTALL_LIBDIR=$pkgdir/usr/lib \
		-DCMAKE_INSTALL_INCLUDEDIR=$pkgdir/usr/include \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		"
}

package() {
	make install $_flags \
		INSTALL="$pkgdir"/usr \
		INSTALL_INCLUDE="$pkgdir"/usr/include/"$pkgname" \
		INSTALL_DOC="$pkgdir"/usr/share/doc/"$pkgname" \
		INSTALL_LIB="$pkgdir"/usr/lib
}

graphblas() {
	pkgdesc="Graph algorithms in the language of linear algebra"
	license="Apache-2.0"

	amove usr/lib/libgraphblas.so.*
}

sha512sums="
8f85c6d63b76cba95707dfa732c51200df7794cb4c2599dbd92100475747b8d02b05089a47096e85c60b89bc852a8e768e0670f24902a82d29494a80ccf2bb5f  SuiteSparse-5.10.1.tar.gz
0bdaed29c7770104eb94d9e60a42fe68b5643c8f958aba4cc6d7996888a83ae75a4e509d0c262264c49d5d9b1ca23a958cc71cfaa5e983b0008e65455a987cac  0001-exclude-metis.patch
cd40b696515b26c95298b435a5111e582dc42c2fa2e8ef9889558467d375b1d19452838b9463df66958e73ddb0c8c0191936e3e952586a3c7d345edb08fa7e62  0002-remove-rpath.patch
"
